clc;
clear all;
close all;

%% INIT
M = 8;
N = 4;

lower = 0.0;
upper = 0.999999999999999;
step = 2^(-M);
fid = fopen('round.csv','w');
fprintf(fid,'%s,', 'order');
fprintf(fid,'%s,', 'A');
fprintf(fid,'%s,','Bin(A)');
fprintf(fid,'%s,','B=RND_NEAR(A)');
fprintf(fid,'%s\n','Bin(B)');
%% SIMULATION

In = lower:step:upper;
%Out = zeros(1,length(In));
for i = 1:length(In)
    A = In(i);
    fprintf(fid,'%d,',i);
    fprintf(fid,'%f,',A);
    binA = bin2str(A,0,M);
    fprintf(fid,'%s,',binA);
    B = rnd_near(A,N);
    fprintf(fid,'%f,',B);
    binB = bin2str(B,0,N);
    fprintf(fid,'%s\n',binB);
end